package com.easyedu.student.controller;

import com.easyedu.core.entity.po.OpenCourse;
import com.easyedu.core.entity.po.StudentSelect;
import com.easyedu.core.util.R;
import com.easyedu.student.entity.DO.StudentGrade;
import com.easyedu.student.service.CourseService;
import com.easyedu.student.service.StudentService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author lmr</br>
 * 课程管理
 **/
@RestController
@RequestMapping("/student/course")
public class CourseController {

    private final CourseService courseService;

    private final StudentService studentService;

    public CourseController(CourseService courseService, StudentService studentService) {
        this.courseService = courseService;
        this.studentService = studentService;
    }

    /**
     * 功能描述:查询可选课程</br>
     * 查询的是 学年开课表 open_course
     *
     * @param instituteId  1 学院id
     * @param departmentId 2 专业id
     * @param schoolYear   3 开放学年 school_year
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/optional")
    public R getOptionalCourse(@RequestParam Long instituteId, @RequestParam Long departmentId,
                               @RequestParam Integer openYear, @RequestParam String schoolYear,
                               @RequestParam String semester) {
        List<OpenCourse> optionalCourse = courseService.getOptionalCourse(openYear, instituteId, departmentId,
                schoolYear,
                semester);
        return R.ok().data(optionalCourse);
    }

    /**
     * 功能描述:查询已选课程</br>
     * 查询的是 学生选课表 student_select
     *
     * @param instituteId   1 学院id
     * @param departmentId  2 专业id
     * @param openYear      3 开课年份 open_year
     * @param schoolYear    4 开放学年 school_year
     * @param semester      5 开放学期
     * @param studentNumber 6 学生序号
     * @return : java.util.List<com.easyedu.api.entity.DO.OpenCourse>
     **/
    @GetMapping("/selection")
    public R getHasSelectCourse(@RequestParam Long instituteId, @RequestParam Long departmentId,
                                @RequestParam Integer openYear, @RequestParam String schoolYear,
                                @RequestParam String semester, @RequestParam Long studentNumber) {
        List<StudentSelect> hasSelectCourse = courseService.getHasSelectCourse(instituteId, departmentId, openYear, schoolYear, semester, studentNumber);
        return R.ok().data(hasSelectCourse);
    }

    /**
     * 功能描述: 查询课程成绩</br>
     * 采用联合查询的形势，查询学生选课表 student_select 和 学年开课表 open_course
     *
     * @param studentNumber 1 学生序号
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/grade")
    public R getStudentGrade(@RequestParam Long studentNumber) {
        List<StudentGrade> studentGrade = studentService.getStudentGrade(studentNumber);
        return R.ok().data(studentGrade);
    }


}
